import { _decorator, Component, Node, Sprite, SpriteFrame, Button } from 'cc';
import { UIManager } from "../utils/UIManager";
import { Constants } from "../data/Constants";
import { AudioManager } from '../audio/AudioManager'
import { CustomEventListener } from "../data/CustomEventListener";
const { ccclass, property } = _decorator;

@ccclass('setDialog')
export class setDialog extends Component {
    @property({
        type: Button,
        displayOrder: 1,
    })
    public soundNode: Button = null!;

    @property({
        type: Button,
        displayOrder: 2,
    })
    public soundNode2: Button = null!;


    @property({
        type: Button,
        displayOrder: 3,
    })
    public musicNode: Button = null!;

    @property({
        type: Button,
        displayOrder: 4,
    })
    public musicNode2: Button = null!;

    @property({
        type: Sprite,
        displayOrder: 5,
    })
    public closeNode: Sprite = null!;

    @property({ type: SpriteFrame })
    private sprite1: SpriteFrame | null = null; // 开

    @property({ type: SpriteFrame })
    private sprite2: SpriteFrame | null = null; // 关


    start() {
        this.updateView()
        console.log('start', 'setDialog')
    }

    show() {
        console.log(3213123123123312)
    }


    updateView() {
        this.handleMusicNode(AudioManager.musicVolume)
        this.handleSoundNode(AudioManager.soundVolume)
    }

    changeSwitch (enevt, type) {
        console.log(type, '类型')
        switch (type) {
            case 'music':
                const musicVolume = AudioManager.musicVolume === 1 ? 0 : 1
                this.handleMusicNode(musicVolume)
                break;
            default:
                const soundVolume = AudioManager.soundVolume === 1 ? 0 : 1
                this.handleSoundNode(soundVolume)
                break;
        }
    }

    handleSoundNode(num) {
        console.log(typeof num, num, 'num')
        AudioManager.setSoundVolume(num)
        if (Number(num) === 1) {
            this.soundNode2.node.active = false
            this.soundNode.node.active = true
        } else {
            this.soundNode.node.active = false
            this.soundNode2.node.active = true
        }
    }

    handleMusicNode(num) {
        AudioManager.setMusicVolume(num)
        if (Number(num) === 1) {
            this.musicNode2.node.active = false
            this.musicNode.node.active = true
        } else {
            this.musicNode.node.active = false
            this.musicNode2.node.active = true
        }
    }

    close() {
        console.log('关闭')
        UIManager.hideDialog(Constants.UIPage.setDialog);
    }

}

